<template>
  <div>
    <el-form :inline="false"
             label-width="100px"
             size="small"
             label-position="right">
      <el-form-item label="节点类型">
        <el-input v-model="localFormData.type" disabled></el-input>
      </el-form-item>
      <el-form-item label="节点ID">
        <el-input v-model="localFormData.id" @input="updateId"></el-input>
      </el-form-item>
      <el-form-item label="节点名称">
        <el-input v-model="localFormData.name" @input="updateName"></el-input>
      </el-form-item>

      <el-form-item v-if="localFormData.type=='bpmn:ServiceTask'" label="类">
        <el-input v-model="localFormData.businessObject.class" @input="updateProperties({'class':localFormData.businessObject.class})"></el-input>
      </el-form-item>


      <!--sequenceFlow-->
      <el-form-item v-if="localFormData.type=='bpmn:SequenceFlow'" label="分支条件">
        <el-input v-model="localFormData.sequenceFlow" @input="updateSequenceFlow"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    name: "NodePropertyPanel",
    data() {
      return {
        bpmnData: {}
      }
    },
    props: {
      modeler: {
        type: Object,
        required: true
      },
      nodeElement: {
        type: Object,
        required: true
      },
      formData:{
        type: Object,
        required: true
      }
    },
    computed:{
      localFormData:{
        get(){
          console.log("getfotDaya",this.formData)
          return this.formData
        }
      }
    },
    watch:{
      nodeElement:{
        handler(){
          if(this.nodeElement.type=="bpmn:StartEvent"){
            this.updateName("开始");
          }
          if(this.nodeElement.type=="bpmn:EndEvent"){
            this.updateName("结束");
          }
        }
      }
    },
    methods: {
      updateProperties(properties){
        this.modeler.get("modeling").updateProperties(this.nodeElement, properties);
      },

      updateId(name) {
        this.updateProperties({id: name});
      },
      updateName(name) {
        this.updateProperties({name: name});
      },

      updateSequenceFlow(val){
        let newCondition = this.modeler.get("moddle").create('bpmn:FormalExpression', {
          body: val
        });
        console.log("updateSequenceFlow",val)
        this.updateProperties({conditionExpression:newCondition});
      }
    }
  }
</script>

<style scoped>

</style>
